import 'package:flutter/material.dart';
import 'package:flutter_ducafecat_news/base/base_mvp_presenter.dart';
import 'package:flutter_ducafecat_news/base/base_mvp_view.dart';
import 'package:flutter_ducafecat_news/base/base_mvp_widget.dart';
import 'package:flutter_ducafecat_news/common/utils/utils.dart';
import 'package:flutter_ducafecat_news/common/widgets/image.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

class NewsPage extends BaseWidget {
  @override
  BaseWidgetState<BasePresenter<BaseMvpView>, BaseWidget> getState() {
    // TODO: implement getState
    return NewsPageState();
  }
}

class NewsPageState extends BaseWidgetState<BasePresenter, NewsPage> {
  @override
  Widget buildWidget(BuildContext context) {
    // TODO: implement buildWidget
    return Container(
      child: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            _buildTopTitleWidget(),
            _bulidBannerWidget(),
            Container(
              padding: EdgeInsets.only(left: 50.w),
              height: 100.h,
              alignment: Alignment.centerLeft,
              decoration: BoxDecoration(
                color: Color(0xFFECECEC),
                borderRadius:
                    new BorderRadius.vertical(top: Radius.elliptical(20, 20)),
              ),
              child: Text(
                "Latest",
                style: TextStyle(fontWeight: FontWeight.bold),
              ),
            ),
            _buildListWidget(),
          ],
        ),
      ),
    );
  }

  Widget _bulidBannerWidget() {
    return Container(
      height: 375.w,
      child: Swiper(
          itemBuilder: (BuildContext context, int index) {
            return ClipRRect(
              borderRadius: BorderRadius.circular(10),
              child: Image.network(
                "https://goss.cfp.cn/creative/vcg/800/version23/VCG41184610501.jpg",
                fit: BoxFit.fill,
              ),
            );
          },
          itemCount: 6,
          pagination: new SwiperPagination(),
          loop: true,
          index: 0,
          autoplay: true,
          viewportFraction: 0.8,
          // 当前视窗展示比例 小于1可见上一个和下一个视窗
          scale: 0.8,
          // 两张图片之间的间隔
          duration: 2000),
    );
  }

  Widget _buildTopTitleWidget() {
    return Container(
        width: double.infinity,
        height: 100.h,
        decoration: BoxDecoration(color: Colors.blue),
        child: Container(
          padding: EdgeInsets.only(left: 50.w),
          height: 100.h,
          alignment: Alignment.centerLeft,
          decoration: BoxDecoration(
            color: Color(0xFFECECEC),
            borderRadius:
                new BorderRadius.vertical(top: Radius.elliptical(20, 20)),
          ),
          child: Text(
            "Featured",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
        ));
  }

  List homeNewtruckDatas = [1, 2,3,5];

  Widget _buildListWidget() {
    return Container(
        child: Column(
      children: homeNewtruckDatas.map((item) {
        return Column(
          children: <Widget>[
            _buildListItemWidget(),
          ],
        );
      }).toList(),
    ));
  }

  Widget _buildListItemWidget() {
    return Container(
      margin: EdgeInsets.fromLTRB(20, 0, 20, 10),
      padding: EdgeInsets.all(25.h),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: new BorderRadius.all(new Radius.circular(10.0)),
      ),
      child: Row(
        children: <Widget>[
          ImageCached(
            'https://goss.cfp.cn/creative/vcg/800/version23/VCG41184610501.jpg',
            width: 180,
            height: 180,
          ),
          SizedBox(
            width: 20.w,
          ),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
                Text(
                  "NKN 双周报 2020年3月1日至",
                  style: TextStyle(
                    fontSize: 30.sp,
                  ),
                  maxLines: 2,
                ),
                SizedBox(
                  height: 10.h,
                ),
                Text("NKN 双周报 2020年3月1日至",
                    style: TextStyle(fontSize: 26.sp, color: Colors.grey[400])),
                SizedBox(
                  height: 10.h,
                ),
                Text("周三 0304 2020",
                    style: TextStyle(fontSize: 26.sp, color: Colors.grey[400])),
              ],
            ),
          )
        ],
      ),
    );
  }

  @override
  void initData() {
    // TODO: implement initData
    setOtherHeight(getBottomNavigationBarHeight(context));
    setAppbarActions(_buildActions());
    setAppBarText('NEWS');
  }

  @override
  BasePresenter<BaseMvpView> initPresenter() {
    // TODO: implement initPresenter
    return null;
  }

  @override
  void showSuccess(data) {
    // TODO: implement showSuccess
  }
}

List<Widget> _buildActions() {
  return <Widget>[
    IconButton(
        icon: Icon(Icons.share),
        onPressed: () {
          print("Alarm");
        })
  ];
}

@override
void initData() {
  // TODO: implement initData
}

@override
BasePresenter<BaseMvpView> initPresenter() {
  // TODO: implement initPresenter
  return null;
}

@override
void showSuccess(data) {
  // TODO: implement showSuccess
}
